package com.STS.ELearning.DAO
{
	
	
	import com.STS.ELearning.VO.KullanicilarVO;
	
	import flash.data.SQLConnection;
	import flash.data.SQLResult;
	import flash.data.SQLStatement;
	import flash.errors.SQLError;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	import mx.collections.ArrayCollection;
	import mx.collections.ArrayList;
	import mx.controls.Alert;
	
	public class Kullanicilar extends BaseDao
	{
	
	  
		private static var instance:Kullanicilar;
		private static const TABLE_NAME:String="Kullanicilar";
		public static function getInstance():Kullanicilar {
			if( instance == null )
				instance = new Kullanicilar( new SingletonLock );
			return instance;
		}
		
	
		public function Kullanicilar( lock: SingletonLock) {
			
			super(TABLE_NAME);
		}
	
				
		public override function getTableContent(order:String=null,where:String=null,whereParams:Array=null):Array{
			var data:Array=super.getTableContent(order,where,whereParams);
			var arrlist:Array=new Array();
			if(data!=null)
			for each(var item:Object in data)
			{
				arrlist.push( new KullanicilarVO(item));
			}
			return arrlist;
		}
		public function getKullaniciByKullaniciAdi( email:String ):KullanicilarVO {
			
			var text:String = ' (email=@email) ';
			var parameters:Array=[{name:"email",value:email}];
			var data:Array=getTableContent(null,text,parameters);
			if(data != null && data.length>0)
				return data[0] as KullanicilarVO;
			return null;
			
		}
		public function insertRow( rowItem:Object):Boolean {
			var text:String = 'INSERT INTO main.'+TABLE_NAME+'(id,ad, soyad, email, sifre, ilkGirisTarihi, sonGirisTarihi, girisSayisi )'+
				' VALUES ('+super.getId()+',@ad,@soyad,@email,@sifre,@ilkGirisTarihi,@sonGirisTarihi,@girisSayisi );';
			var params:Array = [ {name:"ad", value:rowItem.ad}, {name:"soyad", value:rowItem.soyad}, 
				{name:"email", value:rowItem.email}, {name:"sifre", value:rowItem.sifre}, 
				{name:"ilkGirisTarihi", value:rowItem.ilkGirisTarihi}, 
				{name:"sonGirisTarihi", value:rowItem.sonGirisTarihi}, {name:"girisSayisi", value:rowItem.girisSayisi} ];
			return executeSingleResult(text,params,rowItem,"id");
			
		}
		public function updateRow( rowItem:Object):Boolean {
			var text:String = 'UPDATE main.'+TABLE_NAME+' SET  ad = @ad, soyad = @soyad, email = @email, '+
				'sifre = @sifre, ilkGirisTarihi = @ilkGirisTarihi, sonGirisTarihi = @sonGirisTarihi,'+
				' girisSayisi = @girisSayisi WHERE main.'+TABLE_NAME+'.id = @id;';
			var params:Array= [ {name:"id", value:rowItem.id}, {name:"ad", value:rowItem.ad}, {name:"soyad", value:rowItem.soyad}, {name:"email", value:rowItem.email}, {name:"sifre", value:rowItem.sifre}, {name:"ilkGirisTarihi", value:rowItem.ilkGirisTarihi}, {name:"sonGirisTarihi", value:rowItem.sonGirisTarihi}, {name:"girisSayisi", value:rowItem.girisSayisi} ] ;
			return executeSingleResult(text,params);
		}
		
		
		
		public function deleteRow( rowItem:Object):Boolean {
			var text:String = 'DELETE FROM main.'+TABLE_NAME+' WHERE main.'+TABLE_NAME+'.id = @id;';
			var params:Array = [ {name:"id", value:rowItem.id} ];
			return executeSingleResult(text,params);
		}
		
		
	}

	

}

class SingletonLock {}
